package cn.ai.boot.config;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * @author jie.zhao@dms365.com
 * @Date 2025/6/28 15:38
 */
public class Test11212TTT {


    public static void main(String[] args) {


        List<Map<String, Object>> dataList = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("PCM_COMPONENT_PATH", "A");
        map.put("PCM_MATERIAL_STATUS", "A");
        dataList.add(map);

        Map<String, Object> mapB = new HashMap<>();
        mapB.put("PCM_COMPONENT_PATH", "B");
        mapB.put("PCM_MATERIAL_STATUS", "EXCLUDE");
        dataList.add(mapB);

        Map<String, Object> mapC = new HashMap<>();
        mapC.put("PCM_COMPONENT_PATH", "mapC");
        mapC.put("PCM_MATERIAL_STATUS", "S");
        dataList.add(mapC);

        boolean removeExcludeMaterialStatus = true;
        // 材料状态为EXCLUDE的数据
        List<Map<String, Object>> excludeDataList = new ArrayList<>();
        // 过滤异常数据,如果要过滤，则排序前先从dataList中移除，排完序再加回来，因为要清除EXCLUDE的数据的pcm_startorend_element要素值
        dataList.removeIf(x -> {
            if (MapUtils.getString(x, "PCM_COMPONENT_PATH").equals("A")) {
                return true;
            }
            if (removeExcludeMaterialStatus &&
                    "EXCLUDE".equals(MapUtils.getString(x, "PCM_MATERIAL_STATUS"))) {
                setComponentFields(x);
                excludeDataList.add(x);
                return true;
            }
            return false;
        });


        System.out.println(dataList);
        System.out.println(excludeDataList);

        // 排完序再加回来，因为要清除EXCLUDE的数据的pcm_startorend_element要素值
        if (removeExcludeMaterialStatus) {
            dataList.addAll(excludeDataList);
        }


        System.out.println(dataList);
        System.out.println(excludeDataList);

    }


    // 封装字段清理方法
    private static void setComponentFields(Map<String, Object> data) {
        data.put("PCM_STARTOREND_ELEMENT", "sss");
    }
}
